import { getCategoryAPI, getCategoryByIdAPI } from '@/apis/category'
export const useCategoryStore = defineStore('category', () => {
    // 导航列表的数据管理
    // state 导航列表数据
    const categoryList = ref([])
    const categoryListById = ref([])

    // action 获取导航数据的方法
    const getCategory = async () => {
        const res = await getCategoryAPI()
        categoryList.value = res.data
    }
    onMounted(()=>getCategory());

    const getCategoryById = async (id) => {
        const res = await getCategoryByIdAPI(id)
        let updatedCategoryList = Array.isArray(res.data) ? res.data : [];
        categoryListById.value = updatedCategoryList;
    }

    return {
        categoryList,
        getCategory,
        categoryListById,
        getCategoryById
    }
})